package com.example.wnn.utils;

import net.bramp.ffmpeg.FFmpegUtils;
import net.bramp.ffmpeg.FFprobe;
import net.bramp.ffmpeg.probe.FFmpegFormat;
import net.bramp.ffmpeg.probe.FFmpegProbeResult;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class AnalysisHtmlUtils {



    public static void analysis(String htmlTxt) throws Exception {

        Document docDesc = Jsoup.parse(htmlTxt);

        //根据标签ID 获取标签内容
        Elements elements = docDesc.getElementsByTag("audio");

        for (Element element : elements) {
            Attributes attributes = element.attributes();
            String url = attributes.get("src");
            System.out.println(url);

        }
    }



    public static void main(String[] args) throws Exception {
         String htmltxt ="<!-- Audio Player HTML --><p></p><p>GT Podcast with Mulan</p><p><audio src=\"https://1253985869.vod2.myqcloud.com/39f921f7vodgzp1253985869/5b50ea3d243791579761309483/dP1jXjLS83EA.mp3\" controls=\"controls\"></audio></p><p>Welcome to another episode of the GT Podcast with Mulan – a one-stop shop for the Global Times’ take on top China and global news.<br/><br/>On today’s podcast:<br/><br/>A Chernobyl moment in the US state of Ohio? What <a href=\"https://enapp.globaltimes.cn/article/1285450\" target=\"_self\" nid=\"1285450\" appprop=\"1\">Chinese experts say</a> about the danger of the toxic chemicals – and about toxic politics in the US?<br/><br/>In economic news, the <a href=\"https://enapp.globaltimes.cn/article/1285502\" target=\"_self\" nid=\"1285502\" appprop=\"1\">head of the International Monetary Fund’s office in China</a> shares his view on China’s economic recovery and what it means for the world.<br/><br/>An in-depth interview with <a href=\"https://enapp.globaltimes.cn/article/1285365\" target=\"_self\" nid=\"1285365\" appprop=\"1\">Chinese Ambassador to France Lu Shaye</a> – and a reminder for Europe: don’t try to &quot;hit China with an ideological stick&quot; and expect cooperation in return.<br/><br/>Also, has Australia become a proxy of the US? <a href=\"https://enapp.globaltimes.cn/article/1285143\" target=\"_self\" nid=\"1285143\" appprop=\"1\">Former Australian diplomat John Lander</a> has some dire warnings about Canberra engaging as a proxy for the US in a war against China.&nbsp;&nbsp;<br/><br/>Finally, <a href=\"https://enapp.globaltimes.cn/article/1285004\" target=\"_self\" nid=\"1285004\" appprop=\"1\">from our Culture Beat</a>, an awkward reality for Western film companies that seek to reduce reliance on China: their films’ success largely depends on the Chinese market.22</p>";
        analysis(htmltxt);

        getTime();


    }

    private static void  getTime(){

        try {
            FFprobe ffprobe = new FFprobe("/Users/wenzheng/Desktop/ff/ffprobe");
            FFmpegProbeResult in = ffprobe.probe("https://1253985869.vod2.myqcloud.com/39f921f7vodgzp1253985869/5b50ea3d243791579761309483/dP1jXjLS83EA.mp3");
            FFmpegFormat format = in.getFormat();
            long l =(long)  format.duration;
            Integer duration = Integer.valueOf(String.valueOf(l));
            System.out.println(duration);
        } catch (IOException e) {
            e.printStackTrace();
        }

        }

}
